USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-Insert]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	Insert record into table [dbo].[Stores]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-Insert]
	/*@Store_RowNumber int =Null OUTPUT , 
	@Store_ID uniqueidentifier =Null  , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@Store_Notes varchar(max) =Null  , 
	@IsSellPlace tinyint =0  , 
	@Store_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Stores](/*[Store_ID], [StoreClassification_ID], [Store_Code], [Store_NameAr], [Store_NameEn], [Store_Address], [Store_Notes], [IsSellPlace], [Store_Search]*/)
	VALUES     (/*@Store_ID, @StoreClassification_ID, @Store_Code, @Store_NameAr, @Store_NameEn, @Store_Address, @Store_Notes, @IsSellPlace, @Store_Search*/)

	/*SELECT @Store_RowNumber = [Store_RowNumber]
    FROM [dbo].[Stores]
    WHERE  ( [Store_ID] =@Store_ID )
	AND  ( [StoreClassification_ID] =@StoreClassification_ID )
	AND  ( [Store_Code] =@Store_Code )
	AND  ( [Store_NameAr] =@Store_NameAr )
	AND  ( [Store_NameEn] =@Store_NameEn )
	AND  ( [Store_Address] =@Store_Address )
	AND  ( [Store_Notes] =@Store_Notes )
	AND  ( [IsSellPlace] =@IsSellPlace )
	AND  ( [Store_Search] =@Store_Search )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-update]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	Update record in table [dbo].[Stores]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-update]
	/*@Store_RowNumber int =Null OUTPUT , 
	@Store_ID uniqueidentifier =Null  , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@Store_Notes varchar(max) =Null  , 
	@IsSellPlace tinyint =0  , 
	@Store_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Stores] SET 
		/*[Store_ID] =@Store_ID, 
		[StoreClassification_ID] =@StoreClassification_ID, 
		[Store_Code] =@Store_Code, 
		[Store_NameAr] =@Store_NameAr, 
		[Store_NameEn] =@Store_NameEn, 
		[Store_Address] =@Store_Address, 
		[Store_Notes] =@Store_Notes, 
		[IsSellPlace] =@IsSellPlace, 
		[Store_Search] =@Store_Search*/
		/*WHERE ([Store_ID] = @Store_ID)*/
	/**/

	/*SELECT @Store_RowNumber = [Store_RowNumber]
    FROM [dbo].[Stores]
	WHERE ([Store_ID] = @Store_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-Insert-Update]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	Insert OR Update record into table [dbo].[Stores]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-Insert-Update]
	/*@Store_RowNumber int =Null OUTPUT , 
	@Store_ID uniqueidentifier =Null  , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@Store_Notes varchar(max) =Null  , 
	@IsSellPlace tinyint =0  , 
	@Store_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Stores] 
					/*WHERE ([Store_ID] = @Store_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Stores](/*[Store_ID], [StoreClassification_ID], [Store_Code], [Store_NameAr], [Store_NameEn], [Store_Address], [Store_Notes], [IsSellPlace], [Store_Search]*/)
		VALUES     (/*@Store_ID, @StoreClassification_ID, @Store_Code, @Store_NameAr, @Store_NameEn, @Store_Address, @Store_Notes, @IsSellPlace, @Store_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Stores] SET 
			/*[Store_ID] =@Store_ID, 
			[StoreClassification_ID] =@StoreClassification_ID, 
			[Store_Code] =@Store_Code, 
			[Store_NameAr] =@Store_NameAr, 
			[Store_NameEn] =@Store_NameEn, 
			[Store_Address] =@Store_Address, 
			[Store_Notes] =@Store_Notes, 
			[IsSellPlace] =@IsSellPlace, 
			[Store_Search] =@Store_Search*/
			/*WHERE ([Store_ID] = @Store_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Store_RowNumber = [Store_RowNumber]
    FROM [dbo].[Stores]
	WHERE ([Store_ID] = @Store_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-Delete]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	delete records from table [dbo].[Stores] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-Delete]
	/*@Store_RowNumber int =null  , 
	@Store_ID uniqueidentifier =null  , 
	@StoreClassification_ID uniqueidentifier =null  , 
	@Store_Code varchar(50) =null  , 
	@Store_NameAr varchar(300) =null  , 
	@Store_NameEn varchar(300) =null  , 
	@Store_Address varchar(500) =null  , 
	@Store_Notes varchar(max) =null  , 
	@IsSellPlace tinyint =null  , 
	@Store_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Stores]
	WHERE /*( [Store_RowNumber] = ISNULL(@Store_RowNumber, [Store_RowNumber]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [StoreClassification_ID] = ISNULL(@StoreClassification_ID, [StoreClassification_ID]) )
	AND ( [Store_Code] like ISNULL(@Store_Code, [Store_Code]) )
	AND ( [Store_NameAr] like ISNULL(@Store_NameAr, [Store_NameAr]) )
	AND ( [Store_NameEn] like ISNULL(@Store_NameEn, [Store_NameEn]) )
	AND ( [Store_Address] like ISNULL(@Store_Address, [Store_Address]) )
	AND ( [Store_Notes] like ISNULL(@Store_Notes, [Store_Notes]) )
	AND ( [IsSellPlace] = ISNULL(@IsSellPlace, [IsSellPlace]) )
	AND ( [Store_Search] like ISNULL(@Store_Search, [Store_Search]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-Select]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	select records from table [dbo].[Stores] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-Select]
	/*@Store_RowNumber int =null  , 
	@Store_ID uniqueidentifier =null  , 
	@StoreClassification_ID uniqueidentifier =null  , 
	@Store_Code varchar(50) =null  , 
	@Store_NameAr varchar(300) =null  , 
	@Store_NameEn varchar(300) =null  , 
	@Store_Address varchar(500) =null  , 
	@Store_Notes varchar(max) =null  , 
	@IsSellPlace tinyint =null  , 
	@Store_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Stores]
	WHERE /*( [Store_RowNumber] = ISNULL(@Store_RowNumber, [Store_RowNumber]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [StoreClassification_ID] = ISNULL(@StoreClassification_ID, [StoreClassification_ID]) )
	AND ( [Store_Code] like ISNULL(@Store_Code, [Store_Code]) )
	AND ( [Store_NameAr] like ISNULL(@Store_NameAr, [Store_NameAr]) )
	AND ( [Store_NameEn] like ISNULL(@Store_NameEn, [Store_NameEn]) )
	AND ( [Store_Address] like ISNULL(@Store_Address, [Store_Address]) )
	AND ( [Store_Notes] like ISNULL(@Store_Notes, [Store_Notes]) )
	AND ( [IsSellPlace] = ISNULL(@IsSellPlace, [IsSellPlace]) )
	AND ( [Store_Search] like ISNULL(@Store_Search, [Store_Search]) )*/
END
GO
-- =============================================
